<div class="leftbody">
    <section class="col-md-8 col-sm-12 col-xs-12" ng-controller="loginCtrl">
        <form name="loginForm" ng-submit="processLoginForm(loginForm.$valid)" novalidate>
            <h3><a href="/">主页</a>/用户登录 &nbsp;<small class="text-danger hide" id="errorInfo">用户名密码错误！</small></h3>
            <div class="form-group">
                <input type="text" class="form-control" name="userName" id="userName" ng-minlength="6" ng-maxlength="12" ng-model="loginFormData.userName" ng-pattern="/^[a-zA-Z][a-zA-Z0-9_]{5,11}$/" placeholder="请输入用户名" required>
                <label ng-cloak for="inputError" class="control-label text-danger" ng-show="loginForm.userName.$invalid && !loginForm.userName.$pristine"><i class="glyphicon glyphicon-exclamation-sign"></i>用户名为6-12个英文数字组合</label>
            </div>
            <div class="form-group">
                <input type="password" class="form-control" id="userPassword" name="password"placeholder="请输入密码" ng-pattern="/[?!a-zA-Z0-9_]{6,16}/" ng-maxlength="16" ng-model="loginFormData.password" required>
                <label ng-cloak for="inputError" class="control-label text-danger" ng-show="loginForm.password.$invalid && !loginForm.password.$pristine"><i class="glyphicon glyphicon-exclamation-sign"></i>6-16位，只能包含字母数字下划线</label>
            </div>
            <div>
                <button class="btn btn-block btn-info" ng-disabled="loginForm.$invalid">登录</button>
                <p style="margin-top: 10px"><a href="/users/forgetPsd">忘记密码</a></p>
            </div>
        </form>
    </section>
    <section>
        <%- include rightmain%>
    </section>
</div>
<script>
    var webApp = angular.module('webApp',[]);
    webApp.controller('loginCtrl',function ($scope,$http) {
        $scope.processLoginForm = function (isVaild) {
            if(isVaild){
                //如果表单内容格式正确
                $http({
                    method:'POST',
                    url:'/users/doLogin',
                    data:$.param($scope.loginFormData),
                    headers:{'Content-Type':'application/x-www-form-urlencoded'}
                }).success(function (data) {
                    if(data === 'success'){
                        alert('登录成功');
                        window.location = '/';
                    } else {
                        $('#errorInfo').removeClass('hide').text(data);
                    }
                })
            } else {
                alert('输入有误！');
            }
        }
    })
</script>